package com.zxl.live.screen.call.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;

import com.zxl.live.screen.R;
import com.zxl.live.screen.call.model.bean.ThemeBean;
import com.zxl.live.screen.call.ui.fragment.ThemePreviewFragment;
import com.zxl.live.tools.base.BaseAppCompatActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/8.
 */

public class CallThemeDetailActivity extends BaseAppCompatActivity implements View.OnClickListener, ThemePreviewFragment.OnAnimListener {

    private ImageView mBackView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_theme_detail);
        mBackView = (ImageView) findViewById(R.id.nav_back);
        mBackView.setOnClickListener(this);
        ViewPager viewPager = (ViewPager) findViewById(R.id.preview_view_pager);
        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                mBackView.setTranslationX(0);
            }
        });
        ArrayList<ThemeBean> data = getIntent().getParcelableArrayListExtra("data");
        int position = getIntent().getIntExtra("position", 0);
        viewPager.setAdapter(new Adapter(data));
        viewPager.setOffscreenPageLimit(position);
        viewPager.setCurrentItem(position);
    }

    @Override
    public void onClick(View v) {
        onBackPressed();
    }

    @Override
    public void onApplyBtnShow(ThemePreviewFragment fragment) {
    }

    @Override
    public void onBackShow() {
        mBackView.animate().translationX(0.0F).setDuration(400L).setInterpolator(new DecelerateInterpolator()).setStartDelay(500).start();
    }

    @Override
    public void onBackDismiss() {
        mBackView.animate().translationX(-mBackView.getWidth() * 1.5f).setDuration(400L).setInterpolator(new DecelerateInterpolator()).setStartDelay(0L).start();
    }

    class Adapter extends FragmentPagerAdapter {

        private List<ThemeBean> mList;

        public Adapter(List<ThemeBean> mList) {
            super(getSupportFragmentManager());
            this.mList = mList;
        }

        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public Fragment getItem(int position) {
            ThemePreviewFragment fragment = new ThemePreviewFragment();
            fragment.setThemeBean(mList.get(position));
            fragment.setmOnAnimListener(CallThemeDetailActivity.this);
            return fragment;
        }
    }



}
